package demo_JUC.LockObj;

import java.util.concurrent.TimeUnit;

public class demo001 {
    public static void main(String[] args) {
        Phone phone = new Phone();
        // 以下程序，会先sendSms，后call
        // 原因在于synchronized锁的phone

        new Thread(()->{phone.sendSms();}, "A").start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(()->{phone.call();}, "B").start();
    }

    static class Phone{

        public synchronized void sendSms(){
            try {
                TimeUnit.SECONDS.sleep(4);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("sendSms");
        }
        public synchronized void call(){
            System.out.println("call");
        }
    }
}
